home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / replaceNode.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  2.9 KB  |  89 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  11 February 1998
  22. //  Author:         cdt
  23. //
  24. //  Description:
  25. //      This implements the replace node based on attribute names.
  26. //
  27.  
  28. proc int arrayMatch( string $array[], string $match )
  29. {
  30.     for ($item in $array)
  31.         if ($item == $match)
  32.             return true;
  33.  
  34.     return false;
  35. }
  36.  
  37. global proc replaceNode( string $originalNode, string $replaceNode )
  38. {
  39.     // Copy the scalar values
  40.  
  41.     string $originalAttrs[] =
  42.         `listAttr -scalar -multi -read -visible $originalNode`;
  43.  
  44.     string $replaceAttrs[] =
  45.         `listAttr -scalar -multi -write -visible $replaceNode`;
  46.  
  47.     for ($attr in $originalAttrs) {
  48.         if (arrayMatch($replaceAttrs, $attr)) {
  49.             float $value = `getAttr ($originalNode+"."+$attr)`;
  50.             catch(`setAttr ($replaceNode+"."+$attr) $value`);
  51.         }
  52.     }
  53.  
  54.     string $connections[];
  55.  
  56.     // Process the source connections
  57.  
  58.     $connections = `listConnections -source true -destination false
  59.         -connections true -plugs true $originalNode`;
  60.  
  61.     for ($i = 0; $i < size($connections); $i += 2) {
  62.         string $originalPlug = $connections[$i];
  63.         string $srcPlug = $connections[$i+1];
  64.  
  65.         string $replacePlug =
  66.             substitute($originalNode, $originalPlug, $replaceNode);
  67.         
  68.         catch(`connectAttr $srcPlug $replacePlug`);
  69.     }
  70.  
  71.     // Process the destination connections
  72.  
  73.     $connections = `listConnections -source false -destination true
  74.         -connections true -plugs true $originalNode`;
  75.  
  76.     for ($i = 0; $i < size($connections); $i += 2) {
  77.         string $originalPlug = $connections[$i];
  78.         string $dstPlug = $connections[$i+1];
  79.  
  80.         string $replacePlug =
  81.             substitute($originalNode, $originalPlug, $replaceNode);
  82.  
  83.         // First, break connections between original and dstPlug.
  84.         catch(`disconnectAttr $originalPlug $dstPlug`);
  85.  
  86.         catch(`connectAttr $replacePlug $dstPlug`);
  87.     }
  88. }
  89.